<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/mine.css">
</head>
<body>

<!--导航-->
<nav th:replace="admin/_fragments :: menu(2)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui header item">Volcreate</h2>
            <!--icon的地址-->
            <a href="index.html" class="m-item item m-mobile-hide"><i class="home icon"></i>管理首页</a>
            <a href="blogs.html" class="m-item item m-mobile-hide"><i class="blogger icon"></i>博客管理</a>
            <a href="category.html" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类管理</a>
            <a href="index.html" class="m-item item m-mobile-hide"><i class="bars icon"></i>更多</a>
            <!--登录管理-->
            <div class="right m-item m-mobile-hide menu">
                <div class="ui dropdown item">
                    <div class="text"><img class="ui avatar image" src="../../static/images/c1.jpeg" alt="">zxc</div>
                    <i class="dropdown icon"></i>
                    <div class="menu"><a href="#" class="item">注销</a></div>
                </div>
            </div>
        </div>
    </div>
    <!--手机端适配-->
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>


<!--副导航-->
<div th:replace="admin/_fragments :: sub_menu(3)"   class="ui attached pointing menu">
    <div class="ui container">
        <div class="left menu">
            <a href="#" target="_blank" class="item">主首页</a>
        </div>
        <div class="right menu m-padded-lr-responsive">
            <a href="#"  class="item">编辑</a>
            <a href="#"  class="item">查询</a>
            <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
        </div>
    </div>
</div>


<!--中间内容-->
<div class="m-container m-padded-tb-big">
    <div class="ui container">

        <!--搜索栏-->
        <div th:if="${session.user.type} <= 2"  method="post" class="ui secondary segment form">
            <input type="hidden" name="page" value="">
            <div class="inline fields">
                <!--输入标题，模糊查找-->
                <div class="field">
                    <label>
                        <input type="text" name="title" placeholder="标题">
                    </label>
                </div>
                <!--选择类别-->
                <div class="field">

                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item" th:each="type : ${types}" data-value="1" th:data-value="${type.id}" th:text="${type.name}">类别</div>
                            </div>
                        </div>

                        <button id="clear-btn" class="ui compact button">clear</button>
                    </div>
                </div>
                <!--是否推荐-->
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" name="recommendable" id="recommendable">
                        <label for="recommendable">推荐</label>
                    </div>
                </div>
                <!--进行搜索-->
                <div class="field">
                    <button type="button" id="search-btn" class="ui mini  basic button"><i class="search icon"></i>搜索</button>
                </div>
            </div>
        </div>


        <div id="table-container">
            <table th:fragment="blogList" class="ui compact center aligned table">
                <thead>
                <tr>
                    <th></th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>博客状态</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,iterStat : ${page.list}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">学习linux</td>
                    <td th:text="${blog.type.name}">Linux</td>
                    <td th:text="${blog.recommendable} ? '是' : '否'">是</td>
                    <td th:text="${blog.published} ? '发布' : '草稿'">发布</td>
                    <td th:text="${blog.gmtModified}">2020-8-19 12:10</td>
                    <td>
                        <a href="#" th:href="@{/admin/blogs/{id}/edit(id=${blog.id})}"  class="ui mini basic green button">编辑</a>
                        <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}"  class="ui mini basic red button">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <th colspan="7">
                        <a href="#" th:href="@{/admin/blogs/edit}" class="ui mini right floated labeled icon button">
                            <i class="edit outline icon"></i> 新增
                        </a>
                        <div class="ui mini left floated pagination menu" th:if="${page.pages}>1">
                            <a onclick="page(this)" th:attr="data-page=${page.pageNum}-1" class=" item" th:unless="${page.isFirstPage}"><i class="left chevron icon"></i>上一页</a>
                            <a class="item" onclick="page(this)" th:attr="data-page=${pageNum}" th:href="@{/admin/tag(page=${pageNum})}" th:each="pageNum : ${page.navigatepageNums}" th:text="${pageNum}" th:if="${page.navigatePages} lt 5" >1</a>
                            <a onclick="page(this)" th:attr="data-page=${page.pageNum}+1" class=" item" th:unless="${page.isLastPage}">下一页<i class="right chevron icon"></i></a>
                        </div>
                    </th>
                </tr>
                </tfoot>
            </table>
            <div class="ui Blue message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${message}">恭喜，操作成功！</p>
            </div>
        </div>

    </div>
</div>



<!----------------JS---------------->
<!--/*/<th:block th:replace="admin/_fragments :: script" >/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="../../static/js/mine.js"></script>
<!--/*/</th:block>/*/-->
<script>

    $(".tabular.menu .item").tab();

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });
    //消息提示关闭初始化
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade');
        });
    $('#clear-btn')
        .on('click', function() {
            $('.ui.type.dropdown')
                .dropdown('clear')
            ;
        })
    ;

    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loaddata();
    }

    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loaddata();
    });

    function loaddata() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
            title : $("[name='title']").val(),
            typeId : $("[name='typeId']").val(),
            recommendable : $("[name='recommendable']").prop('checked'),
            page : $("[name='page']").val()
        });
    }



</script>
<!----------------JS---------------->
</body>
</html>